home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / gs_cidfn.ps < prev    next >
Text File  |  1996-01-10  |  9KB  |  275 lines

  1. %    Copyright (C) 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % ProcSet for implementing CID-keyed fonts.
  16. % When this is run, systemdict is still writable.
  17.  
  18. %**************** This file isn't even close to being usable:
  19. %    - It doesn't include the actual character mapper (BuildGlyph).
  20. %    - CMap support mostly isn't implemented.
  21. %    - It has never been tested on a real font.
  22. %**************** So don't even think of actually trying to use it!
  23.  
  24. /.setlanguagelevel where { pop 2 .setlanguagelevel } if
  25. .currentglobal true .setglobal
  26.  
  27. /GS_CIDInit_ProcSet 30 dict dup begin
  28.  
  29. % ---------------- CIDFont operators ---------------- %
  30.  
  31. /StartData        % <cidfontdict> <(Binary)|(Hex)> <datalength>
  32.             %   StartData -
  33.  { 2 index begin    % CID font dict
  34.    20 dict begin    % temporary dict
  35.    /datalength exch def
  36.    (Hex) eq /hex exch def
  37.    /cidfont exch def
  38.    /startdata currentfile fileposition def
  39.    
  40.     % Read the character data into an array of strings.
  41.     % There's no particular reason to prefer long strings over short,
  42.     % so we just create a separate string for each character.
  43.  
  44.    /charstrings CIDCount array def
  45.    /fontindices FDArray length FDBytes 1 eq { string } { array } ifelse def
  46.    0 1 CIDCount 1 sub
  47.     { /cid exch def
  48.       currentfile FDBytes GDBytes add cid mul startdata add setfileposition
  49.       fontindices cid FDBytes .readint put
  50.       /pos GDBytes .readint def
  51.       FDBytes .readint pop    % skip FD of next entry
  52.       GDBytes .readint pos sub
  53.       dup 0 eq
  54.        { pop null }
  55.        { currentfile pos setfileposition string readstring pop }
  56.       ifelse
  57.       charstrings cid 3 -1 roll put
  58.     }
  59.    for
  60.  
  61.     % Process each font in the FDArray.
  62.     % For Type 3 fonts, just do a definefont with an empty Encoding.
  63.     % For Type 1 fonts, read the Subrs (don't bother to check for
  64.     % duplicates), and set CharStrings to the character data array.
  65.     % We don't support embedded Type 0 fonts, but it isn't clear
  66.     % whether they're allowed anyway.
  67.  
  68.    cidfont /Encoding [ FDArray
  69.     { dup /FontType get 1 eq
  70.        { dup /CharStrings charstrings put
  71.      /Private get
  72.      dup /SubrCount known
  73.       { begin /Subrs [    % Private
  74.         0 1 SubrCount 1 sub
  75.          { SDBytes mul SubrMapOffset add startdata add
  76.            currentfile exch setfileposition
  77.            /pos SDBytes .readint def
  78.            SDBytes .readint pos sub
  79.            currentfile pos setfileposition string readstring pop
  80.          }
  81.         ] readonly def end    % Private
  82.       }
  83.      if pop
  84.        }
  85.       if
  86.       dup /Encoding [] put
  87.       dup /FontName get exch definefont
  88.     }
  89.    forall ] readonly def
  90.  
  91.     % Install the rest of the data in the font.
  92.  
  93.    cidfont /FontType 0 put    % ???
  94.    cidfont /CharStrings charstrings readonly put
  95.    cidfont /FontIndices fontindices readonly put
  96.    FontName cidfont /CIDFont defineresource pop
  97.  
  98.     % Wrap up.
  99.  
  100.    end            % temporary dict
  101.    end            % CID font dict
  102.    end            % resource dict
  103.  } bind def
  104.  
  105. /.readint        % <nbytes> .readint <int>
  106.  { 0 exch { 8 bitshift currentfile read pop add } repeat
  107.  } bind def
  108.  
  109. % ---------------- CMap operators ---------------- %
  110.  
  111. % We create the following structures for character code mapping.
  112. %    Map - a multi-level array indexed by the successive bytes of
  113. %      the character code.  All of the arrays are read-only.
  114.  
  115. % ------ Font-level operators ------ %
  116.  
  117. /begincmap        % - begincmap -
  118.  { /Map 256 array def
  119.  } bind def
  120. /endcmap        % - endcmap -
  121.  { /Map Map .endmap def
  122.  } bind def
  123.  
  124. /begincodespacerange    % <count> begincodespacerange -
  125.  { pop mark
  126.  } bind def
  127. /endcodespacerange    % <code_lo> <code_hi> ... endcodespacerange -
  128.  { counttomark 2 idiv { Map .addcodespacerange } repeat pop
  129.  } bind def
  130.  
  131. /.addcodespacerange    % <code_lo> <code_hi> <map> .addcodespacerange -
  132.  { 2 index length 1 eq
  133.     { 2 { 3 -1 roll 0 get } repeat 1 exch
  134.        { 2 copy 0 put pop } for pop
  135.     }
  136.     { 2 index 0 get 1 3 index 0 get
  137.       6 -2 roll
  138.       2 { 1 1 index length 1 sub getinterval 6 1 roll } repeat
  139.         % Stack: lo hi map lo0 1 hi0
  140.        { 2 copy get null eq { 2 copy 256 array put } if
  141.          4 copy get .addcodespacerange pop
  142.        }
  143.       for pop pop pop
  144.     }
  145.    ifelse
  146.  } bind def
  147. /.endmap        % <map> .endmap <map>
  148.  { dup type /arraytype eq { dup { .endmap exch } forall astore readonly } if
  149.  } bind def
  150.  
  151. /usecmap        % <CMap_name> usecmap -
  152.  { /CMap findresource
  153.    dup length dict copy
  154.    currentdict end exch copy begin
  155.  } bind def
  156.  
  157. % ------ Rearranged font operators ------ %
  158.  
  159. /beginrearrangedfont    % <font_name> <font*> beginrearrangedfont -
  160.  {    (NOT IMPLEMENTED YET.\n) print flush
  161.  } bind def
  162. /endrearrangedfont    % - endrearrangedfont -
  163.  {    (NOT IMPLEMENTED YET.\n) print flush
  164.  } bind def
  165.  
  166. /usefont        % <fontID> usefont -
  167.  {    (NOT IMPLEMENTED YET.\n) print flush
  168.  } bind def
  169.  
  170. /beginusematrix        % <fontID> beginusematrix -
  171.  {    (NOT IMPLEMENTED YET.\n) print flush
  172.  } bind def
  173. /endusematrix        % <matrix> endusematrix -
  174.  {    (NOT IMPLEMENTED YET.\n) print flush
  175.  } bind def
  176.  
  177. % ------ Character name/code selector operators ------ %
  178.  
  179. /beginbfchar        % <count> beginbfchar -
  180.  {    (NOT IMPLEMENTED YET.\n) print flush
  181.  } bind def
  182. /endbfchar        % <code> <to_code|charname> ... endbfchar
  183.  {    (NOT IMPLEMENTED YET.\n) print flush
  184.  } bind def
  185.  
  186. /beginbfrange        % <count> beginbfrange -
  187.  {    (NOT IMPLEMENTED YET.\n) print flush
  188.  } bind def
  189. /endbfrange        % <code_lo> <code_hi> <to_code|(charname*)> ...
  190.             %   endbfrange -
  191.  {    (NOT IMPLEMENTED YET.\n) print flush
  192.  } bind def
  193.  
  194. % ------ CID selector operators ------ %
  195.  
  196. /begincidchar        % <count> begincidchar -
  197.  { pop mark
  198.  } bind def
  199. /endcidchar        % <code> <cid> ... endcidchar -
  200.  { Map counttomark 2 idiv { 2 index 3 1 roll .addcidrange exch pop } repeat
  201.    /Map exch store pop
  202.  } bind def
  203.  
  204. /begincidrange        % <count> begincidrange -
  205.  { pop mark
  206.  } bind def
  207. /endcidrange        % <code_lo> <code_hi> <cid_base> ... endcidrange -
  208.  { Map counttomark 3 idiv { .addcidrange exch pop } repeat
  209.    /Map exch store pop
  210.  } bind def
  211.  
  212. /.addcidrange        % <code_lo> <code_hi> <cid_base> <map> .addcidrange
  213.             %   <cid_next> <map>
  214.  {    % We may be updating a (partly) read-only map from another CMap.
  215.     % If so, implement copy-on-write.
  216.    dup wcheck not { dup length array copy } if
  217.    3 index length 1 eq
  218.     { 2 { 4 -1 roll 0 get } repeat 1 exch
  219.        { 2 copy 4 index put pop exch 1 add exch } for
  220.     }
  221.     { 3 index 0 get 1 4 index 0 get
  222.       7 -2 roll
  223.       2 { 1 1 index length 1 sub getinterval 7 1 roll } repeat
  224.         % Stack: lo hi next map lo0 1 hi0
  225.        { 5 copy get .addcidrange
  226.         % Stack: lo hi oldnext map i next submap
  227.      exch 5 1 roll 4 -1 roll pop
  228.         % Stack: lo hi next map i submap
  229.      3 copy put pop pop
  230.        }
  231.       for 4 -2 roll pop pop
  232.     }
  233.    ifelse
  234.  } bind def
  235.  
  236. % ------ notdef operators ------ %
  237.  
  238. /beginnotdefchar    % <count> beginnotdefchar -
  239.  { pop mark
  240.  } bind def
  241. /endnotdefchar        % <code> <cid> ... endnotdefchar -
  242.  { counttomark 2 idiv { 1 index exch .addnotdefrange } repeat pop
  243.  } bind def
  244.  
  245. /beginnotdefrange    % <count> beginnotdefrange -
  246.  { pop mark
  247.  } bind def
  248. /endnotdefrange        % <code_lo> <code_hi> <cid> ... endnotdefrange -
  249.  { counttomark 3 idiv { .addnotdefrange } repeat pop
  250.  } bind def
  251.  
  252. /.addnotdefrange    % <code_lo> <code_hi> <cid_base> .addnotdefrange -
  253.  {    (NOT IMPLEMENTED YET.\n) print flush
  254.  } bind def
  255.  
  256. % ---------------- Resource category definition ---------------- %
  257.  
  258. end readonly def
  259.  
  260. /defineresource where
  261.  { pop
  262.    [/CIDFont /CMap]
  263.     { /Generic /Category findresource dup length dict copy
  264.       /Category defineresource pop
  265.     }
  266.    forall
  267.    /CIDInit GS_CIDInit_ProcSet /ProcSet defineresource pop
  268.  }
  269. if
  270.  
  271. .setglobal
  272.